
#include "GameTime.h"

namespace FlameEngine
{
	GameTimer::GameTimer():
		m_lastUpdateTime(0),
		m_elapsedTime(0),
		m_totalTime(0),
		m_timeScale(1),
		m_enableDebugAdjust(false),
		m_isPaused(false)
	{
	}

	void GameTimer::Start_()
	{
		m_stopWatch.Start();
	}

	void GameTimer::Update_()
	{
		if(m_isPaused)
			return;

		double elapsedTime = m_stopWatch.GetElapsedTime();
		double deltaElapsedTime = elapsedTime - m_lastUpdateTime;
		if(m_enableDebugAdjust && deltaElapsedTime > 5)
			elapsedTime = 0.0333;
		
		m_elapsedTime = deltaElapsedTime * m_timeScale;
		m_totalTime += m_elapsedTime;
		
		m_lastUpdateTime = elapsedTime;
	}

	void GameTimer::SingleStep()
	{
		if(m_isPaused)
		{
			m_elapsedTime = 1.0 / 30.0 * m_timeScale;
			m_totalTime += m_elapsedTime;
		}
	}


}